package java实验七;
public class 程序一 {
    // 主方法
    public static void main(String[] args) {
        Circle22 circle1 = new Circle22(1);
        System.out.println("The area of the circle of radius " + circle1.radius + " is " + circle1.getArea());

        Circle22 circle2 = new Circle22(25);
        System.out.println("The area of the circle of radius " + circle2.radius + " is " + circle2.getArea());

        Circle22 circle3 = new Circle22(125);
        System.out.println("The area of the circle of radius " + circle3.radius + " is " + circle3.getArea());

        // 修改圆的半径
        circle2.setRadius(100); // 或circle2.radius=100;
        System.out.println("The area of the circle of radius " + circle2.radius + " is " + circle2.getArea());
    }
}

// 定义一个带有两个构造函数的圆类
class Circle22 {
    double radius;

    /** 构造一个半径为1的圆 */
    Circle22() {
        radius = 1;
    }

    /** 构造一个具有指定半径的圆 */
    Circle22(double newRadius) {
        radius = newRadius;
    }

    /** 返回这个圆的面积 */
    double getArea() {
        return radius * radius * Math.PI;
    }

    /** 返回这个圆的周长 */
    double getPerimeter() {
        return 2 * radius * Math.PI;
    }

    /** 设置一个新的半径给这个圆 */
    void setRadius(double newRadius) {
        radius = newRadius;
    }
}